<template>
  <section class="page">
    <headerbar>
      收藏内容
      <!--<span @click="showShareDialog" class="head-btn-text" slot="btn">分享</span>-->
      <broadcastDetail v-if="typeof detail.newsContent !='undefined' && tools.NotIsNull(detail.newsContent.ttsOssUrl)" :detail="detail"/>
    </headerbar>
    <fetchData  class="bg-white" :loading="isLoading" :data="detail"></fetchData>
    <section class="bg-white" v-if="preData.createTime">
      <section class="detail">
        <h1 class="title">{{preData.title}}</h1>
        <p class="date">来源：{{preData.source || '未知'}} <span class="float-right">时间：{{preData.createTime}}</span></p>
        <p class="color-red pdh-2 pdv-1 shortTitle">{{preData.shortTitle}}</p>
        <p class="line"></p>
        <div class="cont-text" v-if="detail.newsContentExt" v-html="detail.newsContentExt.contents">
        </div>
        <p class="pdv-2"></p>
        <viewsUpsComponent v-if="detail.newsContent"></viewsUpsComponent>

      </section>
    </section>



    <section class="bg-white " :class="[{'d-scroll-2head': isComment},{'d-scroll-3head': isInputFocus}]">
      <!--<div class="water-logo" v-if="preData.comments < 1">
        <img src="../../../../static/images/dangjian/home/logo.png" alt="">
      </div>-->

      <commentListComponent v-if="detail.newsContent" :_contentId="detail.newsContent.id" :shareType="0" :isComment="isComment" @onInputFocus="onInputFocus"></commentListComponent>
      <div class="pdv-10"></div>
    </section>

    <!--<liveMsgComponent v-if="preData.id" :detail="preData" :contentId="preData.id" :comments="preData.comments"></liveMsgComponent>-->

  </section>
</template>

<script>
  import commentListComponent from '@/components/common/commentListComponent'
  import viewsUpsComponent from '@/components/common/viewsUpsComponent'
  export default {
    components: {viewsUpsComponent, commentListComponent},
    name: 'myCollectionDetail',
    data () {
      return {
        isLoading: true,
        preData: {},
        detail: {},
        shareDialogInstance: null,
        isInputFocus: false,
        isComment:true,//是否允许评论 true 允许 false 不允许
      }
    },
    created () {
      this.$store.state.flagType = 1
      this.loadData()
      console.log('---------------this.$route.params.id=', this.$route.params.id)
      // this.like(this.$route.params.id)
    },
    methods: {
      onInputFocus(blo) {
        this.isInputFocus = blo;
      },
      showShareDialog () {
        if (!this.shareDialogInstance) {
          this.shareDialogInstance = this.$createShareDialog({
            $props: {
              newsId: this.$route.params.id || this.preData.id,
              newsTitle: this.preData.title,
              type: 0,
              listPic: this.detail.newsContent.listPic
            }
          })
        }
        this.shareDialogInstance.show()
      },
      loadData () {
        this.isLoading = true
        let id = this.$route.params.id
        this.fetchService.contentPageDetail(id).then(res => {
          if (res.code === 0) {
            this.isLoading = false
            this.detail = res.data
            this.$store.state.newsDetail = this.detail.newsContent
            this.$store.state.newsDetail.detail = this.detail
            this.preData = this.detail.newsContent
            if(this.isComment){
              this.isCommentTag(this.detail.newsContent.channelId)
            }
            // if (this.detail.newsContentExt) {
            //   this.historyAdd()
            // }
          }
        })
      },
    // 添加到我的足迹
      historyAdd () {
        let data = {
          contentId: this.detail.newsContentExt.contentId,
          newsType: 0,  // 新闻类型(0图文;1长视频;2音频;3短视频)
        }
        this.fetchService.historyAdd(data).then((res) => {
        })
      },
      isCommentTag(chanelId){
        // this.getDictValue()
        // console.log('this.isComment',this.isComment);
        let data={
          catKey:'HYTT',
          treeKey:'BNPLDLM'
        }
        this.fetchService.dictValue(data).then(res => {
          console.log('this.fetchService.dictValue',res.data)
          if(res.code === 0){
            res.data.forEach(item=>{
              console.log('item.key',item.key);
              console.log(' this.chanelId', chanelId);
              if(item.key == chanelId){
                this.isComment = item.value == 'true' ? true: false
              }
            })
          }
        })
      },
      like (id) {
        let params = {
          contentId: id,
          type: 1
        }
        this.fetchService.updateCount(params).then(res => {
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  @import "@/common/stylus/moon.scss";
</style>
